package rs.networx.dao;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

import rs.networx.entity.Comment;
import rs.networx.entity.Nottification;
import rs.networx.entity.Person;
import rs.networx.entity.Post;

@Stateless
@Local(CommentDao.class)  
public class CommentDaoBean extends GenericDaoBean<Comment, Integer> implements
		CommentDao {

	@EJB
	NottificationDao nottificationDao;

	@Override
	public void addComment(Comment comment) {
		comment = persist(comment);

		Post post = comment.getPost();

		Person owner = post.getOwner();

		Person poster = comment.getCommetator();

		if (!owner.equals(poster)) {
			return;
		}

		Nottification nottification = new Nottification();
		nottification.setOwner(owner);
		nottification.setTargetID(comment.getId());
		nottification
				.setType(rs.networx.enumeration.NottificationCategory.Comment
						.getType());
		nottification.setViewed(false);
		//TODO prepraviti friendRequestID i  testirati
		nottification.setLink("<a href=\"personsReg?showPost=true"
				+ "&friendRequestID=" + comment.getId() + "&nottificationID="
				+ nottification.getId() + "\">" + poster.getFirstName() + " "
				+ poster.getLastName() + " commented on your post: <big>"
				+ post.getTitle() + "</big></a>");
		nottificationDao.persist(nottification);
	}

}
